import React from 'react';
import { Navigate } from 'react-router-dom';

interface ProtectedRouteProps {
    element: JSX.Element;
}

const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ element }) => {
    const token = localStorage.getItem('token');

    // 如果没有 token，则重定向到登录页面，否则渲染元素  
    return token ? element : <Navigate to="/" replace />;
};

export default ProtectedRoute;